//
//  ProjectDetailsViewController.m
//  Bees
//
//  Created by NowYouCanSee on 2019/3/9.
//  Copyright © 2019 xiaohan. All rights reserved.
//

#import "ProjectDetailsViewController.h"
#import "LMJSettingCell.h"
#import "EosService.h"

@interface ProjectDetailsViewController ()
@property (nonatomic,strong) EOSService *eosService;
@property (nonatomic,weak) UIImageView *iconV;
@property (nonatomic,weak) UILabel *nameLab;
@end

@implementation ProjectDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self getData];
}

- (void)getData{
    if (self.tokenId.length) {
        [self.eosService getTokenInfoByTokenId:self.tokenId complete:^(BOOL success, NSString * _Nonnull errorMsg) {
            if (success) {
                [self.iconV sd_setImageWithURL:String_To_URL(self.eosService.tokenProjectModel.logo)];
                self.nameLab.text = self.eosService.tokenProjectModel.symbol;
                LMJWordItem *item1 = [LMJWordItem itemWithTitle:XLocalized(@"项目名称") subTitle:self.eosService.tokenProjectModel.symbol itemOperation:^(NSIndexPath *indexPath) {
                    
                }];
                item1.subTitleColor = UIColorHex(#B5B5B5);
                item1.subTitleFont = kDefaultFont(12);
//                LMJWordItem *item2 = [LMJWordItem itemWithTitle:XLocalized(@"官网") subTitle:@"" itemOperation:^(NSIndexPath *indexPath) {
//
//                }];
//                item2.subTitleColor = UIColorHex(#B5B5B5);
//                item2.subTitleFont = kDefaultFont(12);
                LMJWordItem *item3 = [LMJWordItem itemWithTitle:XLocalized(@"合约地址") subTitle:self.eosService.tokenProjectModel.contract itemOperation:^(NSIndexPath *indexPath) {
                    
                }];
                item3.subTitleColor = UIColorHex(#B5B5B5);
                item3.subTitleFont = kDefaultFont(12);
//                LMJWordItem *item4 = [LMJWordItem itemWithTitle:XLocalized(@"发行时间") subTitle:@"" itemOperation:^(NSIndexPath *indexPath) {
//
//                }];
//                item4.subTitleColor = UIColorHex(#B5B5B5);
//                item4.subTitleFont = kDefaultFont(12);
                LMJWordItem *item5 = [LMJWordItem itemWithTitle:XLocalized(@"总发行量") subTitle:self.eosService.tokenProjectModel.issue_total itemOperation:^(NSIndexPath *indexPath) {
                    
                }];
                item5.subTitleColor = UIColorHex(#B5B5B5);
                item5.subTitleNumberOfLines = 1;
                item5.subTitleFont = kDefaultFont(12);
                LMJWordItem *item6 = [LMJWordItem itemWithTitle:XLocalized(@"总市值") subTitle:self.eosService.tokenProjectModel.valuation itemOperation:^(NSIndexPath *indexPath) {
                    
                }];
                item6.subTitleColor = UIColorHex(#B5B5B5);
                item6.subTitleFont = kDefaultFont(12);
                
                LMJItemSection *section = [LMJItemSection sectionWithItems:@[item1,item3] andHeaderTitle:XLocalized(@"项目信息") footerTitle:nil];
                LMJItemSection *section1 = [LMJItemSection sectionWithItems:@[item5,item6] andHeaderTitle:XLocalized(@"发行信息") footerTitle:nil];
                [self.sections removeAllObjects];
                [self.sections addObject:section];
                [self.sections addObject:section1];
                [self.tableView reloadData];
            }
        }];
    }
}

- (void)setupUI{
    self.title = XLocalized(@"项目详情");
    UIView *headV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, AdaptedWidth(135))];
    UIImageView*imageV=[UIImageView new];
    self.iconV = imageV;
    [headV addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(AdaptedWidth(15));
        make.size.mas_equalTo(CGSizeMake(AdaptedWidth(50), AdaptedWidth(50)));
        make.centerX.mas_equalTo(0);
    }];
    ViewRadius(imageV, AdaptedWidth(25));
    UILabel *lable = [UILabel new];
    self.nameLab = lable;
    lable.font = kBoldFont(16);
    [headV addSubview:lable];
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageV.mas_bottom).offset(AdaptedWidth(10));
        make.centerX.mas_equalTo(0);
    }];
    headV.backgroundColor = UIColor.whiteColor;
    self.tableView.tableHeaderView = headV;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LMJWordItem *item = self.sections[indexPath.section].items[indexPath.row];
    
    
    LMJSettingCell *cell = [LMJSettingCell cellWithTableView:tableView andCellStyle:UITableViewCellStyleSubtitle];
    
    cell.item = item;
    
    return cell;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = UIColorHex(#F7F7F7);
    UILabel *title = [UILabel new];
    title.textColor = UIColorHex(#B5B5B5);
    title.font = kBoldFont(12);
    [view addSubview:title];
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(AdaptedWidth(15));
        make.centerY.mas_equalTo(0);
    }];
    title.text = self.sections[section].headerTitle;;
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20.0f;
}
#pragma mark - getter

- (EOSService*)eosService{
    if (!_eosService) {
        _eosService = [EOSService new];
    }
    return _eosService;
}
@end
